<div [@routerTransition]>
    <div class="content d-flex flex-column flex-column-fluid">
        <sub-header [title]="'Training' | localize" [description]="'TrainingManage' | localize">
            <div role="actions">
                <div class="btn-group dropdown" dropdown *ngIf="isGranted('Pages.Tenant.Coupons.Apply')">
                    <button class="btn btn-primary dropdown-toggle icon-piliangcaozuo" type="button" id="applyButton"
                        data-toggle="dropdown" dropdownToggle aria-haspopup="true" aria-expanded="false">
                        {{l('batchOperation')}}
                    </button>
                    <div class="dropdown-menu" *dropdownMenu aria-labelledby="applyButton" x-placement="bottom-start">
                        <a class="dropdown-item icon-shangxian1" (click)="online()">
                            {{l('onlineBatch')}}
                        </a>
                        <a class="dropdown-item icon-xiaxian1" (click)="offline()">
                            {{l('offlineBatch')}}
                        </a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item icon-shuminghaoshang_xian" (click)="onlineAll()">
                            {{l('onlineAll')}}
                        </a>
                        <a class="dropdown-item icon-shuminghaoxia_xian" (click)="offlineAll()">
                            {{l('offlineAll')}}
                        </a>
                    </div>
                </div>
                <button class="btn btn-primary" (click)="createTraining()"
                    *ngIf="isGranted('Pages.Tenant.Training.Create')">
                    <i class="fa fa-plus"></i>
                    {{l("CreateNewTraining")}}</button>

                <div class="btn-group dropdown" dropdown *ngIf="isGranted('Pages.Tenant.Training')">
                    <button class="btn btn-primary dropdown-toggle icon-excel" type="button" id="port"
                        data-toggle="dropdown" dropdownToggle aria-haspopup="true" aria-expanded="false"
                        [buttonBusy]="exportLoading">
                        {{l('ImportOrExport')}}
                    </button>
                    <div class="dropdown-menu" *dropdownMenu aria-labelledby="port" x-placement="bottom-start">
                        <a class="dropdown-item icon-shuminghaoxia_xian" (click)="goImport()">
                            {{l('import')}}
                        </a>
                        <a class="dropdown-item icon-shuminghaoshang_xian" (click)="goExport()">
                            {{l('export')}}
                        </a>
                    </div>
                </div>
            </div>

        </sub-header>



        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">

                    <div class="row">
                        <form class="horizontal-form" autocomplete="off">
                            <div class="m-form">
                                <div class="row align-items-center mb-4">
                                    <div class="col-3">
                                        <div class="form-group m-form__group align-items-center">
                                            <div class="input-group">
                                                <input [(ngModel)]="filterText" name="filterText" autoFocus
                                                    class="form-control m-input" (keyup.enter)="getTrainings()"
                                                    [placeholder]="l('SearchWithThreeDot')" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 筛选在线/离线  -->
                                    <div class="col-3">
                                        <div class="form-group m-form__group align-items-center">
                                            <div class="input-group">
                                                <select class="form-control" [(ngModel)]="auditStatus"
                                                    name="auditStatus">
                                                    <option value="">
                                                        {{l("All")+' / '+l("online")+' / '+l("offline")}}</option>
                                                    <option [value]="AuditStatus.Offline">{{l("offline")}}</option>
                                                    <option [value]="AuditStatus.Online">{{l("online")}}</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-3">
                                        <div class="form-group m-form__group align-items-center">
                                            <div class="input-group">
                                                <select class="form-control" [(ngModel)]="trainingStatus"
                                                    name="trainingStatus">
                                                    <option value="">
                                                        {{l("All")}}</option>
                                                    <option [value]="TrainingStatus.None">{{l("trainingOffline")}}
                                                    </option>
                                                    <option [value]="TrainingStatus.NotStarted">
                                                        {{l("trainingnotStarted")}}</option>
                                                    <option [value]="TrainingStatus.Overdue">{{l("trainingoverDue")}}
                                                    </option>
                                                    <option [value]="TrainingStatus.Completed">
                                                        {{l("trainingcompleted")}}</option>

                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <div class="input-group">
                                                <button type="button" class="btn btn-primary"
                                                    [buttonBusy]="primengTableHelper.isLoading"
                                                    (click)="getTrainings()">
                                                    <i class="la la-refresh"></i>
                                                    {{l("search")}}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row align-items-center">
                        <!--<Primeng-Datatable-Start>-->
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <!-- resizableColumns="primengTableHelper.resizableColumns" -->
                            <p-table #dataTable (onLazyLoad)="getTrainings($event)" [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage" [(selection)]="couponPublishList"
                                [paginator]="false" [lazy]="true"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th
                                            *ngIf="isGranted('Pages.Tenant.Training.Delete')||isGranted('Pages.Tenant.Training.Edit')">
                                            {{l('Actions')}}</th>
                                        <th style="width: 5.0em">
                                            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
                                        </th>
                                        <th style="width:5%">{{l('RecordId')}}</th>

                                        <th>{{l('no')}}</th>

                                        <th>{{l('name')}}</th>

                                        <th>{{l('lecturer')}}</th>

                                        <th>{{l('department')}}</th>

                                        <th pSortableColumn="creationTime">
                                            {{l('startDate')}}
                                            <p-sortIcon field="creationTime"></p-sortIcon>
                                        </th>

                                        <th pSortableColumn="creationTime">
                                            {{l('startTime')}}
                                            <p-sortIcon field="creationTime"></p-sortIcon>
                                        </th>

                                        <th pSortableColumn="end_time">{{l('endTime')}}
                                            <p-sortIcon field="end_time"></p-sortIcon>
                                        </th>

                                        <th>{{l('remarks')}}</th>

                                        <th>{{l('participants')}}</th>

                                        <th pSortableColumn="auditStatus">{{l('Status')}}
                                            <p-sortIcon field="auditStatus"></p-sortIcon>
                                        </th>

                                        <th pSortableColumn="trainingStatus">
                                            {{l('trainingStatus')}}
                                            <p-sortIcon field="trainingStatus"></p-sortIcon>
                                        </th>

                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record" [attr.trid]="record.id">
                                        <td
                                            *ngIf="isGranted('Pages.Tenant.Training.Delete')||isGranted('Pages.Tenant.Training.Edit')">
                                            <div class="btn-group dropdown" dropdown normalizePosition>
                                                <button class="dropdown-toggle btn btn-sm btn-primary"
                                                    data-toggle="dropdown" dropdownToggle aria-haspopup="true"
                                                    aria-expanded="false">
                                                    <i class="fa fa-cog"></i>
                                                    <span class="caret"></span> {{l("Actions")}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li *ngIf="isGranted('Pages.Tenant.Training.Edit')">
                                                        <a (click)="editTraining(record)"
                                                            class="icon-bianji dropdown-item">{{l('Edit')}}</a>
                                                    </li>
                                                    <li
                                                        *ngIf="isGranted('Pages.Tenant.Training.Delete')&&record['auditStatus']==0">
                                                        <a (click)="deleteTraining(record)"
                                                            class="icon-icon-test dropdown-item">{{l('Delete')}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td>
                                            <p-tableCheckbox [value]="record"></p-tableCheckbox>
                                        </td>
                                        <td> {{transIndex(i)}}</td>
                                        <td> {{record.no}}</td>
                                        <td>
                                            <span>{{record.title}}</span>
                                        </td>
                                        <td>{{record.lecturer}}</td>
                                        <td>{{record.departmentDisplayNames}}</td>
                                        <td>{{record.startTime| date : "yyyy/MM/dd"}}</td>
                                        <td>{{record.startTime| date : "hh:mm:ss"}}</td>
                                        <td>{{record.endTime| date : "hh:mm:ss"}}</td>
                                        <td>{{record.score}}</td>
                                        <td>{{record.participaterCount}}</td>
                                        <td>
                                            <span *ngIf="record['auditStatus']==1"
                                                class="label label-success label-inline">{{l("OnSale")}}</span>
                                            <span *ngIf="record['auditStatus']==0"
                                                class="label label-dark label-inline">{{l("OffSale")}}</span>
                                        </td>

                                        <td>
                                            <span *ngIf="record['trainingStatus']==3&&record['auditStatus']==1"
                                                class="label label-success label-inline">{{l("Completed")}}</span>
                                            <span *ngIf="record['trainingStatus']==1&&record['auditStatus']==1"
                                                class="label label-dark label-inline">{{l("NotStarted")}}</span>
                                            <span *ngIf="record['trainingStatus']==2&&record['auditStatus']==1"
                                                class="label label-dark label-inline">{{l("Overdue")}}</span>
                                            <span *ngIf="record['auditStatus']==0"></span>

                                        </td>

                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="12">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/couponHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getTrainings($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-Datatable-End>-->
                    </div>

                </div>
            </div>

        </div>
        <div *ngIf="isGranted('Pages.Tenant.Coupons.Apply')">
            <div class="modal fade" id="review" tabindex="-1" role="dialog" aria-labelledby="reviewLabel"
                aria-hidden="true">
                <div class="modal-dialog modal-sm" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="reviewLabel">{{l('reviewRequest')}}</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close" (click)="no()">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form>
                                <div class="form-group">
                                    <label for="reason" class="col-form-label">{{l('Message')}}:</label>
                                    <textarea class="form-control" id="reason" name="reason"
                                        [(ngModel)]="apply.reason"></textarea>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" (click)="no()"
                                data-dismiss="modal">{{l('Close')}}</button>
                            <button type="button" class="btn btn-primary" (click)="ok()" [buttonBusy]="busy"
                                [busyText]="l('SavingWithThreeDot')" [disabled]="busy"><i></i>{{l('Send')}}</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 实例化modal -->
        <createOrEditTrainingModal #CreateOrEditTrainingModal (modalSave)="getTrainings()"></createOrEditTrainingModal>
    </div>
</div>